import requests


def getHTMLText(url):#get请求
    try:
        r = requests.get(url)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        return r.text
    except:
        return ""

def postHTMLText(url,data):#post请求
    try:
        r = requests.post(url,data)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        return r.text
    except:
        return ""

def login(data):
    url = "https://api.cqtrust.cn/survey/index.php/login"
    result = eval(postHTMLText(url, data))
    try:
        return result['code'], result['msg'],result['result']['token']
    except:
        return result['code'], result['msg'], " "

def schoolLogin():
    url = 'https://api.cqtrust.cn/survey/index.php/student/school/'
    null = ""
    result = eval(getHTMLText(url))
    result = result['result']
    schoolList = []
    for school in result:
        school = school['name']
        schoolList.append(school)
    return schoolList

if __name__ == '__main__':
    username = "wf"
    password = "12345678"
    school = "NCSS"
    data = {'username': username, 'password': password, 'superiorName': school}
    code, msg, token = login(data)
    naireLogin()